package org.opens.netty.byteBuf;

import io.netty.buffer.ByteBuf;

import io.netty.util.internal.StringUtil;

public class MyByteBufUtil {

    public static void log(ByteBuf byteBuf) {
        int length = byteBuf.readableBytes();
        int rows = length / 16 + (length % 15 == 0 ? 0 : 1) + 4;

        StringBuilder sb = new StringBuilder(rows * 80 * 2)
                .append("read index:").append(byteBuf.readerIndex())
                .append(" write index:").append(byteBuf.writerIndex())
                .append(" capacity index:").append(byteBuf.capacity())
                .append(StringUtil.NEWLINE);
        io.netty.buffer.ByteBufUtil.appendPrettyHexDump(sb, byteBuf);
        System.out.println(sb.toString());
    }

}
